#ifndef _SORT_TEST_H
#define _SORT_TEST_H
#include <string.h>
#include <time.h>
#define SMALL_DATA 5000
#define BIG_DATA 1000000

static void __init_Rand__() __attribute__((constructor));
void __init_Rand__() {
    srand(time(0));
}

int *getRandData(int n) {
    int *arr = (int *)malloc(sizeof(int) * n);
    for(int i = 0; i < n; i++) {
        arr[i] = rand() % 10000;
    }
    return arr;
}

bool check(int *arr, int n) {
    for(int i = 1; i < n; i++) {
        if(arr[i] < arr[i - 1])
            return false;
    }
    return true;
}

#define swap(a, b) { \
    __typeof(a) __c = a; \
    a = b, b = __c; \
}

#define TEST(func, arr, n) { \
    printf("Test %s : ", #func); \
    int *temp = (int *)malloc(sizeof(int) * n); \
    memcpy(temp, arr, sizeof(int) * n); \
    long long start = clock(); \
    func(temp, n); \
    long long end = clock(); \
    if(check(temp, n)) { \
        printf("OK\n"); \
    } else { \
        printf("FAILED\n"); \
    } \
    printf("%d items %lld ms\n", \
         n, \
        (end - start) * 1000 / CLOCKS_PER_SEC); \
    free(temp); \
}

#endif
